@extends('admin.common.base-master')

@section('html-head')
    <style type="text/css">
        .divcss5_list_title{background:#eeeeee; border:1px solid #cccccc; padding:1em;}
        .divcss5_list_content{padding:1em;}
        #tinybox{position:absolute; display:none; padding:10px; background:url('{{url('images/preload.gif')}}') no-repeat 50% 50%;  z-index:2000;}
        #tinymask{position:absolute; display:none; top:0; left:0; height:100%; width:100%; background:#000000; z-index:1500;}
        #tinycontent{background:#ffffff; font-size:1.1em;}

        #n{margin:10px auto; width:920px; border:1px solid #CCC;font-size:12px; line-height:30px;}
        #n a{ padding:0 4px; color:#333}
        .sx{padding: 10px}
        .sx-btn{width: 64px;height: 30px;background-color: #4dbcd3;color: #fff;border: #4dbcd3;border-radius: 7%;}
    </style>
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />
@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">计划列表</a>
        </div>

        <div class="filter-box clearfix">
            <div class="fr" style="margin-top: 10px;">
                <a class="addBtn" href="javascript:void(0)" onclick="upPop()">设置随机</a>
                <a class="addBtn" href="{{route('Admin.Home.planAdd')}}">新增</a>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>计划标题</th>
                    <th>开始时间</th>
                    <th>结束时间</th>
                    <th>抽选时间</th>
                    <th>抽选人数</th>
                    <th>报名费用</th>
                    <th>报名人数</th>
                    <th>实际总金额</th>
                    <th>预计总金额</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                    @if(count($plans) > 0)
                        @foreach($plans as $plan)
                        <tr id="plan_{{$plan->id}}">
                            <td>{{$plan->id}}</td>
                            <td>{{$plan->title}}</td>
                            <td>{{$plan->start_time}}</td>
                            <td>{{$plan->end_time}}</td>
                            <td>{{$plan->select_time}}</td>
                            <td>{{$plan->select_num}}</td>
                            <td>¥{{$plan->amount}}</td>
                            <td>{{$plan->join_count}}</td>
                            <td>¥{{$plan->join_amount}}</td>
                            <td>¥{{$plan->invent_amount}}</td>
                            <td><a class="setstatus" id="status_{{$plan->id}}" href="javascript:void(0);" data-id="{{$plan->id}}">@if($plan->status == 0)<span class="color2">未启动</span> @else <span class="color4">启动</span> @endif</a></td>
                            <td><a class="color2" href="@if($plan){{route('Admin.Home.planAdd')}}?id={{$plan->id}} @endif">编辑</a> <span>|</span> <a href="javascript:void(0);" class="del" data-id="{{$plan->id}}">删除 </a></td>
                        </tr>
                        @endforeach
                    @endif
                </tbody>
                <tfoot class="order-gl">

                </tfoot>
            </table>
        </div>
    </div>

    <!-- 选择添加的课程类型 -->
    <div class="upPop-box">
        <div class="backdrop"></div>
        <div id="upPop" class="info-pop tixian">
            <a class="close" href="javascript:void(0);"></a>
            <h3>设置随机变化值</h3>

            <div class="fill-list">
                <span class="fill-tit">最小(人数)：</span>
                <input class="fill-ipt" type="text" name="min_num" placeholder="最小值不能小于1" id="min_num" value="@if($plan_set){{$plan_set->min_num}}@endif">
            </div>

            <div class="fill-list">
                <span class="fill-tit">最大(人数)：</span>
                <input class="fill-ipt" type="text" name="max_num" placeholder="最大值不能小于2" id="max_num" value="@if($plan_set){{$plan_set->max_num}}@endif">
            </div>

            <div class="fill-list">
                <span class="fill-tit">变化时间(秒)：</span>
                <input class="fill-ipt" type="text" name="change_time" placeholder="最小2秒" id="change_time" value="@if($plan_set){{$plan_set->second}}@else 5 @endif">
            </div>

            <input type="hidden" name="id">
            <div class="fill-list">
                <span class="fill-tit">&nbsp;</span>
                <input class="fill-submit" type="button" id="subThisForm" value="提交">
            </div>
        </div>
    </div>

    <script>
        function upPop() {
            $('.upPop-box').upPop();
        }

        $(function(){
            $(document).on('click','.setstatus',function(){
                var id = $(this).data("id");

                $.ajax({
                    url:'{{route('Api.Admin.Plan.startPlan')}}',
                    type:'post',
                    dataType:'json',
                    data:{plan_id:id},
                    success:function(obj){
                        if(obj.level == "success"){
                            noty({text:obj.message,type:obj.level,timeout:600,
                                callback:{
                                    afterClose:function(){
                                        window.location.reload();
                                    }
                                }
                            });
                        }else{
                            noty({type:obj.level,text:obj.message,timeout:600});
                        }
                    },
                    error:function(obj){
                        console.log(obj);
                    }

                });
            });

            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");

                noty({
                    text: '可能影响计划的进行，你确定要删除吗?',
                    buttons: [
                        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                                $noty.close();
                                $.ajax({
                                    url:'{{route('Api.Admin.Plan.delPlan')}}',
                                    type:'post',
                                    dataType:'json',
                                    data:{id:id},
                                    success:function(obj){
                                        if(obj.level == "success"){
                                            $("#plan_"+id).hide('slow');
                                        }else{
                                            noty({type:obj.level,text:obj.message,timeout:600});
                                        }
                                    },
                                    error:function(obj){
                                        console.log(obj);
                                    }

                                });
                            }
                        },
                        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                                $noty.close();
                            }
                        }
                    ]
                });
            });

            $(document).on('click','#subThisForm',function(){
                var min = $("#min_num").val();
                var max = $("#max_num").val();
                var second = $("#change_time").val();
                $.ajax({
                    url:"{{route('Api.Admin.Page.setPlanNum')}}",
                    type:"post",
                    dataType:"json",
                    data:{min:min,max:max,second:second},
                    success:function (obj) {
                        if(obj.level == "success"){
                            window.location.reload();
                        }else {
                            alert(obj.message);
                        }
                    },
                    error:function (obj) {
                        console.log(obj);
                    }
                });
            });
                {{--var id = $(this).attr("data-id");--}}

                {{--$.ajax({--}}
                    {{--url:'{{url('/api/admin/course/set-course-status')}}',--}}
                    {{--type:'post',--}}
                    {{--dataType:'json',--}}
                    {{--data:{id:id},--}}
                    {{--success:function(obj){--}}
                        {{--if(obj.level == "success"){--}}
                            {{--if(obj.data.status == 0)--}}
                                {{--$("#status_"+id).html('<span class="color2">下架</span>');--}}
                            {{--else--}}
                                {{--$("#status_"+id).html('<span class="color4">上架</span>');--}}
                        {{--}else{--}}
                            {{--noty({type:obj.level,text:obj.message,timeout:600});--}}
                        {{--}--}}
                    {{--},--}}
                    {{--error:function(obj){--}}
                        {{--console.log(obj);--}}
                    {{--}--}}

                {{--});--}}
            {{--});--}}

            {{--$('#sx_btn').click(function () {--}}
                {{--var classify_id = $("#classify option:selected").val();--}}
                {{--var isSeries    = $("#is_series option:selected").val();--}}
                {{--window.location.href = "{{route('Admin.Course.onlineList')}}?classify_id="+classify_id+"&is_series="+isSeries;--}}
            {{--});--}}

            {{--$(document).on("click",".del",function(){--}}
                {{--var id = $(this).attr("data-id");--}}
                {{--$.ajax({--}}
                    {{--url:'{{url('/api/admin/course/delete')}}',--}}
                    {{--type:'post',--}}
                    {{--dataType:'json',--}}
                    {{--data:{id:id},--}}
                    {{--success:function(obj){--}}
                        {{--if(obj.level == "success"){--}}
                            {{--$("#course_"+id).hide('slow');--}}
                        {{--}else{--}}
                            {{--noty({type:obj.level,text:obj.message,timeout:600});--}}
                        {{--}--}}
                    {{--},--}}
                    {{--error:function(obj){--}}
                        {{--console.log(obj);--}}
                    {{--}--}}

                {{--});--}}
            {{--});--}}

            {{--//-------------打开大图---------------------------------}}
            {{--$(document).on('click','.openimg',function(){--}}
                {{--var key = $(this).attr('data-key');--}}

                {{--if(key!== '' && key !== undefined && key !== null){--}}
                    {{--var imageApi = "{{url("/api/file/image-show/")}}";--}}
                    {{--var timestamp = new Date().getTime();--}}
                    {{--var url = imageApi+'/'+key+'?size=300px&t='+timestamp;--}}

                    {{--var content2 = "<img width='300' src='"+url+"' />";--}}
                    {{--TINY.box.show(content2,0,0,0,1);--}}
                {{--}--}}

            {{--});--}}
        });
    </script>
@endsection